package com.sync.syncmasterdata;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.JsonObject;
import com.sync.syncmasterdata.customer.pojo.GspCustomer;
import com.sync.syncmasterdata.customer.service.impl.SyncServiceImpl;
import com.sync.syncmasterdata.product.pojo.gsp.InventoryForGsp;
import com.sync.syncmasterdata.product.pojo.oa.InventoryForOA;
import com.sync.syncmasterdata.product.service.SyncInventoryService;
import com.sync.syncmasterdata.product.service.convert.ProductOAtoWms;
import com.sync.syncmasterdata.vendor.pojo.GspVendor;
import com.sync.syncmasterdata.vendor.service.SyncVendorServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import javax.swing.text.html.parser.Entity;
import java.util.List;

/**
 * gsp 测试
 */
@SpringBootTest
@Slf4j
class SyncMasterDataApplicationTestsForGSP {

    @Autowired
    private SyncServiceImpl syncService;

    @Autowired
    private SyncVendorServiceImpl syncVendorService;

    @Autowired
    private SyncInventoryService syncInventoryService;
    @Autowired
    private ProductOAtoWms productOAtoWms;
    @Autowired
    private ObjectMapper objectMapper;


    @Test
    public void customerForGsp() {
        GspCustomer gspCustomer = new GspCustomer();
        gspCustomer.setBusinessName("盐城市妇幼保健院");
        gspCustomer.setBusinessCode("013209002");
        gspCustomer.setOwner("ZJBS");
        gspCustomer.setBusinessType("KH");
        String ret=syncService.pushGspAccountForAdd(gspCustomer);
        System.out.println("结果返回-----》" + ret);
    }

    @Test
    public void vendorForGsp() {
        GspVendor gspVendor = new GspVendor();
        gspVendor.setBusinessName("上海五色石医学科技有限公司");
        gspVendor.setBusinessCode("N1101155");
        gspVendor.setOwner("ZJBS");
        gspVendor.setBusinessType("GH");
        syncVendorService.pushGspVendorForAdd(gspVendor);

    }

    @Test
    public void goodForGsp() {
        InventoryForGsp inventoryForGsp = new InventoryForGsp();
        inventoryForGsp.setGoodsCode("CL01001");
        inventoryForGsp.setGoodsName("50ML锥形离心管");
        inventoryForGsp.setGoodsRef("430828");
        inventoryForGsp.setGoodsSpec("500/箱");
        inventoryForGsp.setIsFirst("N");
        syncInventoryService.addInvToGsp(inventoryForGsp);
    }

    @Test
    public void goodsAddGSPFromOA() {
        List<InventoryForOA> lists =syncInventoryService.getWorkflowInfo("428045","12368050");
        for (InventoryForOA entity : lists) {
            try {
                log.info("获取到的 OA 对象：{}", objectMapper.writeValueAsString(entity));
                InventoryForGsp[] invWms = productOAtoWms.convertTo(entity);
                for (InventoryForGsp el : invWms) {
                    el.setWTManufacturer("测试用生产企业");
//                    System.out.println("------请求对象------->" + JSONObject.toJSONString(el));
                    String rspWms = syncInventoryService.addInvToGsp(el);
                    System.out.println("推送结果:------>"+rspWms);
                }
            } catch (JsonProcessingException e) {
                e.printStackTrace();
                System.out.println("程序异常");

            }
        }
    }

    @Test
    public void bug1(){
//        String json="{\"id\":3348,\"tongyongmc\":\"遗传性耳聋基因突变检测试剂盒（PCR-反向点杂交法）\",\"kuwei\":\"冷冻库\",\"jiancexmh\":null,\"chanpinlx\":\"SJ01\",\"cunhuobm\":\"SJ010076\",\"chanpinmc\":\"遗传性耳聋基因突变检测试剂盒（PCR-反向点杂交法）\",\"huohao\":\"/\",\"guigexh\":\"25人份/套\",\"zhujildw\":\"010\",\"pinpaiwb\":\"深圳亿立方\",\"shengchanqy\":null,\"shengchanqywb\":\"深圳市亿立方生物技术有限公司\",\"guochanjk\":0,\"yewulx\":\"产品类\",\"chanpinx\":\"新生儿\",\"chanpinz\":\"耳聋基因\",\"xiangmumc\":\"7cebd620d1a84b4193e9c1c1a770e41a\",\"xiangmumcwb\":\"耳聋基因\",\"beizhu\":null,\"shifouylqx\":1,\"shifoucgbh\":0,\"unitName\":\"套\",\"registrationNo\":null,\"explain\":null,\"technicalRequire\":null,\"temperatureRequire\":null,\"shifouts\":0,\"shifoucw\":2,\"tingshou\":null,\"zixiangmc\":\"遗传性耳聋基因突变检测试剂盒（PCR-反向点杂交法）,遗传性耳聋基因突变检测试剂盒（PCR-反向点杂交法）\",\"wenduc1\":\",2\",\"wenduz1\":\"-18,8\",\"wenduc\":null,\"wenduz\":null,\"yujingyxq\":30,\"youxiaoq\":6,\"yanghulx\":1,\"storeType\":1,\"crmid\":null,\"cpid\":null,\"wmscpty\":null}";
        String json="{\"id\": 3348,\n" +
                "    \"tongyongmc\": \"遗传性耳聋基因突变检测试剂盒（PCR-反向点杂交法）\",\n" +
                "    \"kuwei\": \"冷冻库\",\n" +
                "    \"jiancexmh\": null,\n" +
                "    \"chanpinlx\": \"SJ01\",\n" +
                "    \"cunhuobm\": \"SJ010076\",\n" +
                "    \"chanpinmc\": \"遗传性耳聋基因突变检测试剂盒（PCR-反向点杂交法）\",\n" +
                "    \"huohao\": \"/\",\n" +
                "    \"guigexh\": \"25人份/套\",\n" +
                "    \"zhujildw\": \"010\",\n" +
                "    \"pinpaiwb\": \"深圳亿立方\",\n" +
                "    \"shengchanqy\": null,\n" +
                "    \"shengchanqywb\": \"深圳市亿立方生物技术有限公司\",\n" +
                "    \"guochanjk\": 0,\n" +
                "    \"yewulx\": \"产品类\",\n" +
                "    \"chanpinx\": \"新生儿\",\n" +
                "    \"chanpinz\": \"耳聋基因\",\n" +
                "    \"xiangmumc\": \"7cebd620d1a84b4193e9c1c1a770e41a\",\n" +
                "    \"xiangmumcwb\": \"耳聋基因\",\n" +
                "    \"beizhu\": null,\n" +
                "    \"shifouylqx\": 1,\n" +
                "    \"shifoucgbh\": 0,\n" +
                "    \"unitName\": \"套\",\n" +
                "    \"registrationNo\": null,\n" +
                "    \"explain\": null,\n" +
                "    \"technicalRequire\": null,\n" +
                "    \"temperatureRequire\": null,\n" +
                "    \"shifouts\": 0,\n" +
                "    \"shifoucw\": 2,\n" +
                "    \"tingshou\": null,\n" +
                "    \"zixiangmc\": \"遗传性耳聋基因突变检测试剂盒（PCR-反向点杂交法）-1,遗传性耳聋基因突变检测试剂盒（PCR-反向点杂交法）-2\",\n" +
                "    \"wenduc1\": \",2\",\n" +
                "    \"wenduz1\": \"-18,8\",\n" +
                "      \"storeType1\":\"3,5\",\n" +
                "    \"wenduc\": null,\n" +
                "    \"wenduz\": null,\n" +
                "    \"yujingyxq\": 30,\n" +
                "    \"youxiaoq\": 6,\n" +
                "    \"yanghulx\": 1,\n" +
                "    \"storeType\": 1,\n" +
                "    \"crmid\": null,\n" +
                "    \"cpid\": null,\n" +
                "    \"wmscpty\": null\n" +
                "}";
//        InventoryForOA entity = JSONObject.parseObject(json, InventoryForOA.class);
//        InventoryForGsp[] invWms = productOAtoWms.convertTo(entity);
//        System.out.println("临时打印---entity----->" + JSONObject.toJSONString(invWms));
    }

}
